package com.rectcircle.wechat.util;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.rectcircle.wechat.entrance.MsgHandler;
import com.rectcircle.wechat.exception.ConfigException;

/**
 * 
 * servlet相关工具，简化web开发
 * 
 * @author RectCircle
 * @version 0.1<br>
 * 2016年7月28日-上午12:04:27<br>
 * Copyright (c) 2016 RectCircle-版权所有<br>
 *
 */
//TODO 完成文件上传保存
public class ServletTools {
	public static void setEncoding(HttpServletRequest request, HttpServletResponse response, MsgHandler msgHandler, String token) throws IOException, ConfigException{
		request.setCharacterEncoding("UTF-8");
		response.setHeader("content-type","text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
	}
	
	public static String getRequestBody(HttpServletRequest request) {
		BufferedReader br;
		StringBuffer sb = new StringBuffer();
		try {
			br = request.getReader();
			String str;
			while((str = br.readLine()) != null){
				sb.append(str);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}
}
